
module.exports = function(grunt) {

  var matchdep = require('matchdep')

  matchdep.filterDev('grunt-*', './package.json').forEach(grunt.loadNpmTasks)

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
      sass: {
        files: ['assets/sass/**/*.scss'],
        tasks: ['compass'],
        options: {
          spawn: false
        },
      },
      scripts: {
        files: ['assets/javascripts/*.js'],
        tasks: ['browserify']
      }
    },
    compass: {
      dev: {
        options: {
          sassDir: ['assets/sass'],
          cssDir: ['build/css'],
          environment: 'development'
        }
      }
    },
    browserify: {
      dist: {
        files: {
          'build/js/main.js': ['assets/javascripts/main.js']
        }
      }
    },
    browserSync: {
      dev: {
        bsFiles: {
          src : [
            'build/css/*.css',
            'build/*.html'
          ]
        },
        options: {
          watchTask: true,
          server: './'
        }
      }
    },
    uglify: {
      target: {
        files: {
          'build/js/main.js': ['build/js/main.js']
        }
      }
    },
    cssmin: {
      options: {
        shorthandCompacting: false,
        roundingPrecision: -1
      },
      target: {
        files: {
          'build/css/style.css': ['build/css/style.css']
        }
      }
    },
    sass: {
      dist: {
        options: {
          sourcemap: 'none',
          style: 'expanded'
        },
        files: [{
          expand: true,
          cwd: 'assets/sass',
          src: ['*.scss'],
          dest: './build/css',
          ext: '.css'
        }]
      }
    }
  });

  // Default task(s).
  grunt.registerTask('default', ['browserSync', 'watch']);
  grunt.registerTask('build', ['browserify', 'uglify', 'compass', 'cssmin']);

};
